package com.mida.bms.report.controller;

import com.mida.bms.report.entity.DocReportServiceLock;
import com.mida.bms.report.service.DocReportServiceLockService;
import com.mida.bms.report.vo.DocStructTemplateInfoVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import com.mida.tool.common.validator.InsertValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: DocReportServiceLockController
 * @Description: 报告业务锁控制层
 * @Author: wang xiao le
 * @Date: 2021/7/28 10:51
 **/
@RestController
@RequestMapping("/docReportServiceLock")
@CrossOrigin
@Slf4j
public class DocReportServiceLockController {

    @Autowired
    private DocReportServiceLockService docReportServiceLockService;

    /**
     * 添加锁
     *
     * @param docReportServiceLock
     * @return
     */
    @PostMapping(value = "/insert", consumes = {"application/json;charset=UTF-8"})
    public ActionResult insert(@RequestBody DocReportServiceLock docReportServiceLock) {

        ActionResult result = new ActionResult();
        try {
            return docReportServiceLockService.insert(docReportServiceLock);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.BAD_REQUEST.value());
            result.setMessage("添加锁失败");
            return result;
        }
    }

    /**
     * 获取锁
     *
     * @param docReportServiceLock
     * @return
     */
    @PostMapping(value = "/select", consumes = {"application/json;charset=UTF-8"})
    public ListResult<DocReportServiceLock> select(@RequestBody DocReportServiceLock docReportServiceLock) {

        ListResult<DocReportServiceLock> result = new ListResult<>();
        try {
            return docReportServiceLockService.select(docReportServiceLock);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.BAD_REQUEST.value());
            result.setMessage("获取锁失败");
            return result;
        }
    }

    /**
     * 删除锁
     *
     * @param docReportServiceLock
     * @return
     */
    @PostMapping(value = "/delete", consumes = {"application/json;charset=UTF-8"})
    public ActionResult delete(@RequestBody DocReportServiceLock docReportServiceLock) {

        ActionResult result = new ActionResult();
        try {
            result = docReportServiceLockService.delete(docReportServiceLock);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.BAD_REQUEST.value());
            result.setMessage("解锁失败");
            return result;
        }
        return result;
    }

    /**
     * 批量查询锁
     *
     * @param docReportServiceLockList
     * @return
     */
    @PostMapping(value = "/selectLockList", consumes = {"application/json;charset=UTF-8"})
    public ListResult<List<DocReportServiceLock>> selectLockList(@RequestBody List<DocReportServiceLock> docReportServiceLockList) {
        return docReportServiceLockService.selectLockList(docReportServiceLockList);
    }
}
